home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pvm34b3.zip / pvm34b3 / pvmtest / message_passing.c < prev    next >
C/C++ Source or Header  |  1995-05-22  |  38KB  |  1,485 lines

  1. /****************************************/
  2. /*    message_passing.c        */
  3. /*    tests for :            */
  4. /*        head-head        */
  5. /*        triangle        */
  6. /*        funneling        */
  7. /****************************************/
  8.  
  9. #include "pvm_test.h"
  10.  
  11. /********************************/
  12. /*    HEAD TO HEAD        */
  13. /********************************/
  14.  
  15. /*    MASTER    */
  16.  
  17. short head_head(args,host,is_empty,send_mode,route,data_format)
  18. char    **args;
  19. int    host;
  20. int    is_empty;
  21. int    send_mode;
  22. int    route;
  23. int     data_format;
  24. {
  25. int    i;
  26. int    tid;
  27. int    narch;
  28. int    info,ack;
  29. int    *inbuf;
  30. int    *outbuf;
  31. int    nhost;
  32. int    count;
  33. struct    pvmhostinfo *hostp;
  34. int    atid,atag,alen;
  35. struct  timeval t1,t2;
  36. double  Total_time=0;
  37. double  Average_time;
  38.  
  39. inbuf = (int *)malloc(sizeof(int)*messages_length);
  40. outbuf = (int *)malloc(sizeof(int)*messages_length);
  41. /** Check if options possible **/
  42. info = pvm_config(&nhost,&narch,&hostp);
  43. if (info <0)
  44.     {
  45.     fprintf(outfile,"\tpvm_config() : Failed with error %d\n",info); 
  46.     return -1;
  47.     }
  48. if (narch >1)
  49.     {
  50.     if (data_format != PvmDataDefault)
  51.         return NOT_POSSIBLE;
  52.     if (send_mode != SEND)
  53.         return NOT_POSSIBLE;
  54.     }
  55. fprintf(outfile,"%s (%s ) <---> %s (%s )\n",
  56.     hostpool[0],hostarch[0],hostpool[host],hostarch[host]);
  57. info = pvm_spawn(TEST_SLAVE,args,PvmTaskHost,hostpool[host],1,&tid);
  58. if (info <1)
  59.     {
  60.     fprintf(outfile,"\tpvm_spawn() : Failed with error %d for host %s\n", 
  61.         tid,hostpool[host]);
  62.     return -1;
  63.     }
  64.  
  65. info = pvm_initsend(PvmDataDefault);
  66. if (info <0)
  67.     {
  68.     fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  69.     goto fail;
  70.     }
  71. info = pvm_pkint(&messages_length,1,1);
  72. if (info <0)
  73.     {
  74.     fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  75.     goto fail;
  76.     }
  77. info = pvm_send(tid,ACKNOLEDGE);
  78. if (info <0)
  79.     {
  80.     fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  81.         info,hostpool[host]);
  82.     goto fail;
  83.     }
  84. ack = timeout_wait_message(tid,ACKNOLEDGE,host);
  85. if (ack <0)
  86.     goto fail;
  87.  
  88. info = pvm_recv(tid,ACKNOLEDGE);
  89. if (info <0)
  90.     {
  91.     fprintf(outfile,"\tpvm_recv() : Failed with error %d for host %s\n",
  92.         info,hostpool[host]);
  93.     goto fail;
  94.     }
  95.  
  96. info = pvm_setopt(PvmRoute,route);
  97. if (info <0)
  98.     {
  99.     fprintf(outfile,"\tpvm_setopt() : Failed with error %d\n",info);
  100.     goto fail;
  101.     }    
  102.  
  103. if ((is_empty == EMPTY)&&(send_mode == SEND))
  104.     {
  105.     if (timing_total||timing_average)
  106.         gettimeofday(&t1,NULL);
  107.     for(i=0;i< num_messages;i++)
  108.         {
  109.         if ((info = pvm_initsend(data_format))<0)
  110.             {
  111.             fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n");
  112.             goto fail;
  113.             }
  114.         if ((info = pvm_send(tid,HEAD_HEAD)) <0)
  115.             {
  116.             fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  117.                 info,hostpool[host]);
  118.             goto fail;
  119.             }
  120.         for (count=0;count<BUSY_LOOP_PERF;count++)
  121.                     if (pvm_probe(tid,HEAD_HEAD)>0)
  122.                             break;
  123.             if (count== BUSY_LOOP_PERF)
  124.                     {
  125.                     fprintf(outfile,"\tTimeout expired from host %s\n",
  126.                                 hostpool[host]);
  127.                     goto fail;
  128.                     }
  129.         /*
  130.         ack = timeout_wait_message(tid,HEAD_HEAD,host);
  131.         if (ack <0)
  132.             goto fail;
  133.         */
  134.         if ((info = pvm_recv(tid,HEAD_HEAD))<0)
  135.             {
  136.             fprintf(outfile,"\tpvm_recv() : Failed with error %d for host %s\n",
  137.                 info,hostpool[host]);
  138.             goto fail;
  139.             }
  140.         }
  141.     if (timing_total||timing_average)
  142.         gettimeofday(&t2,NULL);
  143.     if (timing_total)
  144.         {
  145.         Total_time = TIME_ELAPSED;
  146.         fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  147.         }
  148.     if (timing_average)
  149.         {
  150.         Average_time = TIME_ELAPSED / ((double)num_messages);
  151.         fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  152.         }
  153.     pvm_kill(tid);
  154.     pvm_setopt(PvmRoute,PvmAllowDirect);
  155.     return 1;
  156.  
  157.     }    
  158. if ((is_empty == EMPTY)&&(send_mode == PSEND))
  159.     {
  160.     if (timing_total||timing_average)
  161.         gettimeofday(&t1,NULL);
  162.     for(i=0;i<num_messages;i++)
  163.         {
  164.         if ((info = pvm_psend(tid,HEAD_HEAD,outbuf,0,PVM_INT))<0)
  165.             {
  166.             fprintf(outfile,"\tpvm_psend() : Failed with error %d for host %s\n",
  167.                 info,hostpool[host]);
  168.             goto fail;
  169.             }
  170.         for (count=0;count<BUSY_LOOP_PERF;count++)
  171.                         if (pvm_probe(tid,HEAD_HEAD)>0)
  172.                                 break;
  173.                 if (count== BUSY_LOOP_PERF)
  174.                         {
  175.                         fprintf(outfile,"\tTimeout expired from host %s\n",
  176.                                 hostpool[host]);
  177.                         goto fail;
  178.                     }
  179.         /*
  180.                 ack = timeout_wait_message(tid,HEAD_HEAD,host);
  181.                 if (ack <0)
  182.                         goto fail;
  183.         */
  184.         if ((info = pvm_precv(tid,HEAD_HEAD,inbuf,0,PVM_INT,&atid,&atag,&alen))<0)
  185.             {
  186.             fprintf(outfile,"\tpvm_precv() : Failed with error %d for host %s\n",
  187.                 info,hostpool[host]);
  188.             goto fail;
  189.             }
  190.         }
  191.     if (timing_total||timing_average)
  192.         gettimeofday(&t2,NULL);
  193.     if (timing_total)
  194.         {
  195.             Total_time = TIME_ELAPSED;
  196.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  197.         }
  198.     if (timing_average)
  199.         {
  200.                Average_time = TIME_ELAPSED / ((double)num_messages);
  201.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  202.         }
  203.     pvm_kill(tid);
  204.     pvm_setopt(PvmRoute,PvmAllowDirect);
  205.     return 1;
  206.     }
  207.  
  208. /*    Here is_empty = NOT_EMPTY */
  209. if (send_mode == PSEND)
  210.     {
  211.     if (timing_total||timing_average)
  212.         gettimeofday(&t1,NULL);
  213.     for(i=0;i<num_messages;i++)
  214.         {
  215.         if ((info = pvm_psend(tid,HEAD_HEAD,outbuf,messages_length,PVM_INT))<0)
  216.             {
  217.             fprintf(outfile,"\tpvm_psend() : Failed with error %d for host %s\n",
  218.                 info,hostpool[host]);
  219.             goto fail;
  220.             }
  221.         for (count=0;count<BUSY_LOOP_PERF;count++)
  222.                         if (pvm_probe(tid,HEAD_HEAD)>0)
  223.                                 break;
  224.                 if (count== BUSY_LOOP_PERF)
  225.                         {
  226.                         fprintf(outfile,"\tTimeout expired from host %s\n",
  227.                                 hostpool[host]);
  228.                         goto fail;
  229.                     }
  230.         /*
  231.                 ack = timeout_wait_message(tid,HEAD_HEAD,host);
  232.                 if (ack <0)
  233.                         goto fail;
  234.         */
  235.         if ((info = pvm_precv(tid,HEAD_HEAD,inbuf,
  236.             messages_length,PVM_INT,&atid,&atag,&alen))<0)
  237.             {    
  238.             fprintf(outfile,"\tpvm_precv() : Failed with error %d for host %s\n",
  239.                 info,hostpool[host]);
  240.             goto fail;
  241.             }
  242.         }
  243.     if (timing_total||timing_average)
  244.         gettimeofday(&t2,NULL);
  245.     if (timing_total)
  246.         {
  247.             Total_time = TIME_ELAPSED;
  248.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  249.         }
  250.     if (timing_average)
  251.         {
  252.               Average_time = TIME_ELAPSED / ((double)num_messages);
  253.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  254.         }
  255.     pvm_kill(tid);
  256.     pvm_setopt(PvmRoute,PvmAllowDirect);
  257.     return 1;
  258.     }
  259.  
  260. /*     Here send_mode == SEND and is_empty = NOT_EMPTY    */
  261. if (timing_total||timing_average)
  262.     gettimeofday(&t1,NULL);
  263. for(i=0;i<num_messages;i++)
  264.     {
  265.     if ((info = pvm_initsend(data_format))<0)
  266.         {
  267.         fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n");
  268.         goto fail;
  269.         }
  270.     if ((info = pvm_pkint(outbuf,messages_length,1)) <0)
  271.         {    
  272.         fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  273.         goto fail;
  274.         }
  275.     if ((info = pvm_send(tid,HEAD_HEAD))<0)
  276.         {
  277.         fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  278.             info,hostpool[host]);
  279.         goto fail;
  280.         }
  281.     for (count=0;count<BUSY_LOOP_PERF;count++)
  282.                 if (pvm_probe(tid,HEAD_HEAD)>0)
  283.                         break;
  284.         if (count== BUSY_LOOP_PERF)
  285.                 {
  286.                 fprintf(outfile,"\tTimeout expired from host %s\n",
  287.                         hostpool[host]);
  288.                 goto fail;
  289.                 }
  290.     /*
  291.         ack = timeout_wait_message(tid,HEAD_HEAD,host);
  292.         if (ack <0)
  293.                 goto fail;
  294.     */
  295.     if ((info = pvm_recv(tid,HEAD_HEAD))<0)
  296.         {
  297.         fprintf(outfile,"\tpvm_recv() : Failed with error %d from host %s\n",
  298.             info,hostpool[host]);
  299.         goto fail;
  300.         }
  301.     if ((info = pvm_upkint(inbuf,messages_length,1))<0)
  302.         {
  303.         fprintf(outfile,"\tpvm_upkint() : Failed with error %d\n",info);
  304.         goto fail;
  305.         }
  306.     }
  307. if (timing_total||timing_average)
  308.     gettimeofday(&t2,NULL);
  309. if (timing_total)
  310.     {
  311.     Total_time = TIME_ELAPSED;
  312.     fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  313.     }
  314. if (timing_average)
  315.     {
  316.     Average_time = TIME_ELAPSED / ((double)num_messages);
  317.     fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  318.     }    
  319. pvm_kill(tid);
  320. pvm_setopt(PvmRoute,PvmAllowDirect);
  321. return 1;
  322.  
  323. fail:
  324.     pvm_setopt(PvmRoute,PvmAllowDirect);
  325.     pvm_kill(tid);
  326.     return -1;
  327.     
  328. }    
  329.  
  330. /*    SLAVE    */
  331. void head_head_slave(is_empty,send_mode,route,data_format)
  332. int    is_empty;
  333. int    send_mode;
  334. int    route;
  335. int    data_format;
  336. {
  337. int    *inbuf;
  338. int    *outbuf;
  339. int    atid,atag,alen;
  340. int    length;
  341.  
  342. pvm_recv(pvm_parent(),ACKNOLEDGE);
  343. pvm_upkint(&length,1,1);
  344. inbuf = (int*)malloc(sizeof(int)*length);
  345. outbuf = (int *)malloc(sizeof(int)*length);
  346.  
  347. pvm_initsend(PvmDataDefault);
  348. pvm_send(pvm_parent(),ACKNOLEDGE);
  349. pvm_setopt(PvmRoute,route);
  350.  
  351.  
  352. if ((is_empty == EMPTY)&&(send_mode == SEND))
  353.     {
  354.     while(1)    
  355.         {    
  356.         pvm_recv(pvm_parent(),HEAD_HEAD);
  357.         pvm_initsend(data_format);
  358.         pvm_send(pvm_parent(),HEAD_HEAD);
  359.         }
  360.     }    
  361. if ((send_mode == PSEND)&&(is_empty == EMPTY))
  362.     {
  363.     while(1)
  364.         {
  365.         pvm_precv(pvm_parent(),HEAD_HEAD,inbuf,0,PVM_INT,&atid,&atag,&alen);
  366.         pvm_psend(pvm_parent(),HEAD_HEAD,outbuf,0,PVM_INT);
  367.         }
  368.     }
  369. if (send_mode == PSEND)
  370.     {    
  371.     while(1)
  372.         {
  373.         pvm_precv(pvm_parent(),HEAD_HEAD,inbuf,length,PVM_INT,&atid,&atag,&alen);
  374.         pvm_psend(pvm_parent(),HEAD_HEAD,outbuf,length,PVM_INT);
  375.         }
  376.     }
  377. while(1)
  378.     {
  379.     pvm_recv(pvm_parent(),HEAD_HEAD);
  380.     pvm_upkint(inbuf,length,1);
  381.     pvm_initsend(data_format);
  382.     pvm_pkint(outbuf,length,1);
  383.     pvm_send(pvm_parent(),HEAD_HEAD);
  384.     }
  385. }
  386.  
  387.  
  388.  
  389. /********************************/
  390. /*    TRIANGLE        */
  391. /********************************/
  392.  
  393. /*    MASTER    */
  394.  
  395. short triangle(args,host1,host2,is_empty,send_mode,route,data_format)
  396. char    **args;
  397. int    host1;
  398. int    host2;
  399. int    is_empty;
  400. int    send_mode;
  401. int    route;
  402. int     data_format;
  403. {
  404. int    i;
  405. int    tid1;
  406. int    tid2;
  407. int    narch;
  408. int    info,ack;
  409. int    *inbuf;
  410. int    *outbuf;
  411. int    you_are_the_first=1;
  412. int    you_are_the_second=2;
  413. int    nhost;
  414. struct  timeval t1,t2;
  415. double  Total_time=0;
  416. double  Average_time;
  417. int    count;
  418. struct    pvmhostinfo *hostp;
  419. int    atid,atag,alen;
  420.  
  421. inbuf = (int *)malloc(sizeof(int)*messages_length);
  422. outbuf = (int *)malloc(sizeof(int)*messages_length);
  423.  
  424. /** Check if options possible **/
  425. info = pvm_config(&nhost,&narch,&hostp);
  426. if (info <0)
  427.     {
  428.     fprintf(outfile,"\tpvm_config() : Failed with error %d\n",info);
  429.     return -1;
  430.     }
  431. if (narch >1)
  432.     {
  433.     if (data_format != PvmDataDefault)
  434.         return NOT_POSSIBLE;
  435.     if (send_mode != SEND)
  436.         return NOT_POSSIBLE;
  437.     }
  438.  
  439. fprintf(outfile,"%s (%s ) ---> %s (%s ) ---> %s (%s ) --->\n",
  440.     hostpool[0],hostarch[0],
  441.     hostpool[host1],hostarch[host1],
  442.     hostpool[host2],hostarch[host2]);
  443. info = pvm_spawn(TEST_SLAVE,args,PvmTaskHost,hostpool[host1],1,&tid1);
  444. if (info <1)
  445.     {
  446.     fprintf(outfile,"\tpvm_spawn() : Failed with error %d for host %s\n",
  447.         tid1,hostpool[host1]);
  448.     return -1;
  449.     }
  450. info = pvm_spawn(TEST_SLAVE,args,PvmTaskHost,hostpool[host2],1,&tid2);
  451. if (info <1)
  452.     {
  453.     fprintf(outfile,"\tpvm_spawn() : Failed with error %d for host %s\n",
  454.         tid2,hostpool[host2]);
  455.     pvm_kill(tid1);
  456.     return -1;
  457.     }
  458. /*    First Slave */
  459. info = pvm_initsend(PvmDataDefault);
  460. if (info <0)
  461.     {
  462.     fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  463.     goto fail;
  464.     }
  465. info = pvm_pkint(&tid2,1,1);
  466. if (info <0)
  467.     {
  468.     fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  469.     goto fail;
  470.     }
  471. info = pvm_send(tid1,ACKNOLEDGE);
  472. if (info <0)
  473.     {
  474.     fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  475.         info,hostpool[host1]);
  476.     goto fail;
  477.     }
  478. info = pvm_initsend(PvmDataDefault);
  479. if (info <0)
  480.     {
  481.     fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  482.     goto fail;
  483.     }
  484. info = pvm_pkint(&you_are_the_first,1,1);
  485. if (info <0)
  486.     {
  487.     fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  488.     goto fail;
  489.     }
  490. info = pvm_send(tid1,ACKNOLEDGE);
  491. if (info <0)
  492.     {
  493.     fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  494.         info,hostpool[host1]);
  495.     goto fail;
  496.     }
  497. info = pvm_initsend(PvmDataDefault);
  498. if (info <0)
  499.     {
  500.     fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  501.         goto fail;
  502.         }
  503. info = pvm_pkint(&messages_length,1,1);
  504. if (info <0)
  505.         {
  506.         fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  507.         goto fail;
  508.         }
  509. info = pvm_send(tid1,ACKNOLEDGE);
  510. if (info <0)
  511.         {
  512.         fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  513.                 info,hostpool[host1]);
  514.         goto fail;
  515.         }
  516.  
  517.  
  518. /*    Second Slave */
  519. info = pvm_initsend(PvmDataDefault);
  520. if (info <0)
  521.     {
  522.     fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  523.     goto fail;
  524.     }
  525. info = pvm_pkint(&tid1,1,1);
  526. if (info <0)
  527.     {
  528.     fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  529.     goto fail;
  530.     }
  531. info = pvm_send(tid2,ACKNOLEDGE);
  532. if (info <0)
  533.     {
  534.     fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  535.         info,hostpool[host1]);
  536.     goto fail;
  537.     }
  538. info = pvm_initsend(PvmDataDefault);
  539. if (info <0)
  540.     {
  541.     fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  542.     goto fail;
  543.     }
  544. info = pvm_pkint(&you_are_the_second,1,1);
  545. if (info <0)
  546.     {
  547.     fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  548.     goto fail;
  549.     }
  550. info = pvm_send(tid2,ACKNOLEDGE);
  551. if (info <0)
  552.     {
  553.     fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  554.         info,hostpool[host1]);
  555.     goto fail;
  556.     }
  557. info = pvm_initsend(PvmDataDefault);
  558. if (info <0)
  559.     {
  560.         fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  561.         goto fail;
  562.         }
  563. info = pvm_pkint(&messages_length,1,1);
  564. if (info <0)
  565.         {
  566.         fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  567.         goto fail;
  568.         }
  569. info = pvm_send(tid2,ACKNOLEDGE);
  570. if (info <0)
  571.         {
  572.         fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  573.                 info,hostpool[host1]);
  574.         goto fail;
  575.         }
  576.  
  577. /* Acknoledgements */
  578.  
  579. ack = timeout_wait_message(tid1,ACKNOLEDGE,host1);
  580. if (ack <0)
  581.     goto fail;
  582.  
  583. info = pvm_recv(tid1,ACKNOLEDGE);
  584. if (info <0)
  585.     {
  586.     fprintf(outfile,"\tpvm_recv() : Failed with error %d for host %s\n",
  587.         info,hostpool[host1]);
  588.     goto fail;
  589.     }
  590.  
  591. ack = timeout_wait_message(tid2,ACKNOLEDGE,host2);
  592. if (ack <0)
  593.     goto fail;
  594.  
  595. info = pvm_recv(tid2,ACKNOLEDGE);
  596. if (info <0)
  597.     {
  598.     fprintf(outfile,"\tpvm_recv() : Failed with error %d for host %s\n",
  599.         info,hostpool[host2]);
  600.     goto fail;
  601.     }
  602. /*    Test Body */
  603.  
  604. info = pvm_setopt(PvmRoute,route);
  605. if (info <0)
  606.     {
  607.     fprintf(outfile,"\tpvm_setopt() : Failed with error %d\n",info);
  608.     goto fail;
  609.     }    
  610.  
  611. if ((is_empty == EMPTY)&&(send_mode == SEND))
  612.     {
  613.     if (timing_total||timing_average)
  614.         gettimeofday(&t1,NULL);
  615.     for(i=0;i< num_messages;i++)
  616.         {
  617.         if ((info = pvm_initsend(data_format))<0)
  618.             {
  619.             fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n");
  620.             goto fail;
  621.             }
  622.         if ((info = pvm_send(tid1,TRIANGLE)) <0)
  623.             {
  624.             fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  625.                 info,hostpool[host1]);
  626.             goto fail;
  627.             }
  628.         for (count=0;count<BUSY_LOOP_PERF;count++)
  629.                         if (pvm_probe(tid2,TRIANGLE)>0)
  630.                                 break;
  631.                 if (count== BUSY_LOOP_PERF)
  632.                         {
  633.                         fprintf(outfile,"\tTimeout expired from host %s\n",
  634.                                 hostpool[host2]);
  635.                         goto fail;
  636.             }
  637.         /*
  638.                 ack = timeout_wait_message(tid2,TRIANGLE,host2);
  639.                 if (ack <0)
  640.                         goto fail;
  641.         */
  642.         if ((info = pvm_recv(tid2,TRIANGLE))<0)
  643.             {
  644.             fprintf(outfile,"\tpvm_recv() : Failed with error %d for host %s\n",
  645.                 info,hostpool[host2]);
  646.             goto fail;
  647.             }
  648.         }
  649.     if (timing_total||timing_average)
  650.         gettimeofday(&t2,NULL);
  651.     if (timing_total)
  652.         {
  653.             Total_time = TIME_ELAPSED;
  654.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  655.         }
  656.     if (timing_average)
  657.         {
  658.         Average_time = TIME_ELAPSED / ((double)num_messages);
  659.                 fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  660.         }
  661.     pvm_kill(tid1);
  662.     pvm_kill(tid2);
  663.     pvm_setopt(PvmRoute,PvmAllowDirect);
  664.     return 1;
  665.  
  666.     }    
  667. if ((is_empty == EMPTY)&&(send_mode == PSEND))
  668.     {
  669.     if (timing_total||timing_average)
  670.         gettimeofday(&t1,NULL);
  671.     for(i=0;i<num_messages;i++)
  672.         {
  673.         if ((info = pvm_psend(tid1,TRIANGLE,outbuf,0,PVM_INT))<0)
  674.             {
  675.             fprintf(outfile,"\tpvm_psend() : Failed with error %d for host %s\n",
  676.                 info,hostpool[host1]);
  677.             goto fail;
  678.             }
  679.         for (count=0;count<BUSY_LOOP_PERF;count++)
  680.                         if (pvm_probe(tid2,TRIANGLE)>0)
  681.                                 break;
  682.                 if (count== BUSY_LOOP_PERF)
  683.                         {
  684.                         fprintf(outfile,"\tTimeout expired from host %s\n",
  685.                                 hostpool[host2]);
  686.                         goto fail;
  687.                         }
  688.         /*
  689.         ack = timeout_wait_message(tid2,TRIANGLE,host2);
  690.                 if (ack <0)
  691.                         goto fail;
  692.         */
  693.         if ((info = pvm_precv(tid2,TRIANGLE,inbuf,0,PVM_INT,&atid,&atag,&alen))<0)
  694.             {
  695.             fprintf(outfile,"\tpvm_precv() : Failed with error %d for host %s\n",
  696.                 info,hostpool[host2]);
  697.             goto fail;
  698.             }
  699.         }
  700.     if (timing_total||timing_average)
  701.         gettimeofday(&t2,NULL);
  702.     if (timing_total)
  703.         {
  704.             Total_time = TIME_ELAPSED;
  705.                fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  706.         }
  707.     if (timing_average)
  708.         {
  709.             Average_time = TIME_ELAPSED / ((double)num_messages);
  710.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  711.         }
  712.     pvm_kill(tid1);
  713.         pvm_kill(tid2);
  714.     pvm_setopt(PvmRoute,PvmAllowDirect);
  715.     return 1;
  716.     }
  717.  
  718. /*    Here is_empty = NOT_EMPTY */
  719. if (send_mode == PSEND)
  720.     {
  721.     if (timing_total||timing_average)
  722.         gettimeofday(&t1,NULL);
  723.     for(i=0;i<num_messages;i++)
  724.         {
  725.         if ((info = pvm_psend(tid1,TRIANGLE,outbuf,messages_length,PVM_INT))<0)
  726.             {
  727.             fprintf(outfile,"\tpvm_psend() : Failed with error %d for host %s\n",
  728.                 info,hostpool[host1]);
  729.             goto fail;
  730.             }
  731.         for (count=0;count<BUSY_LOOP_PERF;count++)
  732.                         if (pvm_probe(tid2,TRIANGLE)>0)
  733.                                 break;
  734.                 if (count== BUSY_LOOP_PERF)
  735.                         {
  736.                         fprintf(outfile,"\tTimeout expired from host %s\n",
  737.                                 hostpool[host2]);
  738.                         goto fail;
  739.                         }
  740.         /*
  741.         ack = timeout_wait_message(tid2,TRIANGLE,host2);
  742.                 if (ack <0)
  743.                         goto fail;
  744.         */
  745.         if ((info = pvm_precv(tid2,TRIANGLE,inbuf,
  746.             messages_length,PVM_INT,&atid,&atag,&alen))<0)
  747.             {    
  748.             fprintf(outfile,"\tpvm_precv() : Failed with error %d for host %s\n",
  749.                 info,hostpool[host2]);
  750.             goto fail;
  751.             }
  752.         }
  753.     if (timing_total||timing_average)
  754.         gettimeofday(&t2,NULL);
  755.     if (timing_total)
  756.         {
  757.             Total_time = TIME_ELAPSED;
  758.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  759.         }
  760.     if (timing_average)
  761.         {
  762.             Average_time = TIME_ELAPSED / ((double)num_messages);
  763.                fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  764.         }
  765.     pvm_kill(tid1);
  766.         pvm_kill(tid2);
  767.     pvm_setopt(PvmRoute,PvmAllowDirect);
  768.     return 1;
  769.     }
  770.  
  771. /*     Here send_mode == SEND and is_empty = NOT_EMPTY    */
  772. if (timing_total||timing_average)
  773.     gettimeofday(&t1,NULL);
  774. for(i=0;i<num_messages;i++)
  775.     {
  776.     if ((info = pvm_initsend(data_format))<0)
  777.         {
  778.         fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n");
  779.         goto fail;
  780.         }
  781.     if ((info = pvm_pkint(outbuf,messages_length,1)) <0)
  782.         {    
  783.         fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  784.         goto fail;
  785.         }
  786.     if ((info = pvm_send(tid1,TRIANGLE))<0)
  787.         {
  788.         fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  789.             info,hostpool[host1]);
  790.         goto fail;
  791.         }
  792.     for (count=0;count<BUSY_LOOP_PERF;count++)
  793.                         if (pvm_probe(tid2,TRIANGLE)>0)
  794.                                 break;
  795.                 if (count== BUSY_LOOP_PERF)
  796.                         {
  797.                         fprintf(outfile,"\tTimeout expired from host %s\n",
  798.                                 hostpool[host2]);
  799.                         goto fail;
  800.                         }
  801.     /*
  802.     ack = timeout_wait_message(tid2,TRIANGLE,host2);
  803.         if (ack <0)
  804.                 goto fail;
  805.     */
  806.     if ((info = pvm_recv(tid2,TRIANGLE))<0)
  807.         {
  808.         fprintf(outfile,"\tpvm_recv() : Failed with error %d from host %s\n",
  809.             info,hostpool[host2]);
  810.         goto fail;
  811.         }
  812.     if ((info = pvm_upkint(inbuf,messages_length,1))<0)
  813.         {
  814.         fprintf(outfile,"\tpvm_upkint() : Failed with error %d\n",info);
  815.         goto fail;
  816.         }
  817.     }
  818. if (timing_total||timing_average)
  819.     gettimeofday(&t2,NULL);
  820. if (timing_total)
  821.     {
  822.     Total_time = TIME_ELAPSED;
  823.     fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  824.     }
  825. if (timing_average)
  826.     {
  827.     Average_time = Total_time / ((double)num_messages);
  828.     fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  829.     }
  830. pvm_kill(tid1);
  831. pvm_kill(tid2);
  832. pvm_setopt(PvmRoute,PvmAllowDirect);
  833. return 1;
  834.  
  835. fail:
  836.     pvm_kill(tid1);
  837.     pvm_kill(tid2);
  838.     pvm_setopt(PvmRoute,PvmAllowDirect);
  839.     return -1;
  840.     
  841. }    
  842.  
  843. /*    SLAVE    */
  844. void triangle_slave(is_empty,send_mode,route,data_format)
  845. int    is_empty;
  846. int    send_mode;
  847. int    route;
  848. int    data_format;
  849. {
  850. int    *inbuf;
  851. int    *outbuf;
  852. int    rank,to,from,tidother;
  853. int    atid,atag,alen;
  854. int    length;
  855.  
  856. pvm_recv(pvm_parent(),ACKNOLEDGE);
  857. pvm_upkint(&tidother,1,1);
  858. pvm_recv(pvm_parent(),ACKNOLEDGE);
  859. pvm_upkint(&rank,1,1);
  860. pvm_recv(pvm_parent(),ACKNOLEDGE);
  861. pvm_upkint(&length,1,1);
  862.  
  863. inbuf = (int *)malloc(sizeof(int)*length);
  864. outbuf = (int *)malloc(sizeof(int)*length);
  865.  
  866. if (rank == 1)
  867.     {
  868.     to=tidother;    
  869.     from = pvm_parent();
  870.     }
  871. else
  872.     {
  873.     to = pvm_parent();
  874.     from = tidother;
  875.     }
  876. pvm_initsend(PvmDataDefault);
  877. pvm_send(pvm_parent(),ACKNOLEDGE);
  878.  
  879. pvm_setopt(PvmRoute,route);
  880.  
  881. if ((is_empty == EMPTY)&&(send_mode == SEND))
  882.     {
  883.     while(1)
  884.         {    
  885.         pvm_recv(from,TRIANGLE);
  886.         pvm_initsend(data_format);
  887.         pvm_send(to,TRIANGLE);
  888.         }
  889.     }    
  890. if ((send_mode == PSEND)&&(is_empty == EMPTY))
  891.     {
  892.     while(1)
  893.         {
  894.         pvm_precv(from,TRIANGLE,inbuf,0,PVM_INT,&atid,&atag,&alen);
  895.         pvm_psend(to,TRIANGLE,outbuf,0,PVM_INT);
  896.         }
  897.     }
  898. if (send_mode == PSEND)
  899.     {    
  900.     while(1)
  901.     {
  902.         pvm_precv(from,TRIANGLE,inbuf,length,PVM_INT,&atid,&atag,&alen);
  903.         pvm_psend(to,TRIANGLE,outbuf,length,PVM_INT);
  904.         }
  905.     }
  906. while(1)
  907.     {
  908.     pvm_recv(from,TRIANGLE);
  909.     pvm_upkint(inbuf,length,1);
  910.     pvm_initsend(data_format);
  911.     pvm_pkint(outbuf,length,1);
  912.     pvm_send(to,TRIANGLE);
  913.     }
  914. }
  915.  
  916.  
  917. /********************************/
  918. /*      FUNNELING        */
  919. /********************************/
  920.  
  921. /*      MASTER     */
  922.  
  923. short funneling(args,array_of_index,length,is_empty,send_mode,route,data_format)
  924. char    **args;
  925. int     *array_of_index;
  926. int    length;
  927. int     is_empty;
  928. int     send_mode;
  929. int     route;
  930. int     data_format;
  931. {
  932. int     i,j;
  933. int     *tid;
  934. int     narch;
  935. int     info,ack;
  936. int     *inbuf;
  937. int     *outbuf;
  938. int     *effective_array_of_index;
  939. int    number_of_process;
  940. int    nhost;
  941. struct    pvmhostinfo *hostp;
  942. struct  timeval t1,t2;
  943. double  Total_time=0;
  944. double  Average_time;
  945. int    count;
  946. int    atid,atag,alen;
  947.  
  948. inbuf = (int *)malloc(sizeof(int)*messages_length);
  949. outbuf = (int *)malloc(sizeof(int)*messages_length);
  950.  
  951. number_of_process = (*masters)[atoi(args[0])-1].num_req_hosts;
  952. tid = (int *)malloc(number_of_process*sizeof(int));
  953. effective_array_of_index=(int *)malloc(number_of_process*sizeof(int));
  954. /** Check if options possible **/
  955. info = pvm_config(&nhost,&narch,&hostp);
  956. if (info <0)
  957.     {
  958.     fprintf(outfile,"\tpvm_config() : \
  959.         Failed with error %d\n",info);
  960.     free(tid);
  961.     free(effective_array_of_index);    
  962.     return -1;
  963.     }
  964. if (narch >1)
  965.     {
  966.     if (data_format != PvmDataDefault)
  967.         {
  968.         free(effective_array_of_index);
  969.         free(tid);
  970.         return NOT_POSSIBLE;
  971.         }    
  972.     if ((send_mode != SEND)&&(send_mode != MCAST))
  973.         {
  974.         free(effective_array_of_index);
  975.         free(tid);
  976.         return NOT_POSSIBLE;
  977.         }
  978.     }
  979. for (i=0;i<length;i++)
  980.     effective_array_of_index[i] = array_of_index[i];
  981. for (i=length;i<number_of_process;i++)
  982.         effective_array_of_index[i]=array_of_index[i% length];
  983.  
  984. fprintf(outfile,"%s (%s )\n",
  985.         hostpool[0],hostarch[0]);
  986. for (i=1;i<number_of_process;i++)
  987.     fprintf(outfile,"\t\t ---> %s (%s )\n",
  988.         hostpool[effective_array_of_index[i]],
  989.         hostarch[effective_array_of_index[i]]);
  990.  
  991. for (i=1;i<number_of_process;i++)
  992.     {
  993.     info = pvm_spawn(TEST_SLAVE,args,PvmTaskHost,
  994.         hostpool[effective_array_of_index[i]],1,&(tid[i]));
  995.     if (info <1)
  996.         {
  997.         fprintf(outfile,"\tpvm_spawn() : Failed with error %d for host %s\n",
  998.             tid[i],hostpool[effective_array_of_index[i]]);
  999.         goto fail;
  1000.         }
  1001.     info = pvm_initsend(PvmDataDefault);
  1002.     if (info <0)
  1003.         {
  1004.         fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  1005.         goto fail;
  1006.         }
  1007.     info = pvm_pkint(&messages_length,1,1);
  1008.     if (info <0)
  1009.         {
  1010.         fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  1011.         goto fail;
  1012.         }
  1013.     info = pvm_send(tid[i],ACKNOLEDGE);
  1014.     if (info <0)
  1015.         {
  1016.         fprintf(outfile,"\tpvm_send() : Failed with error %d on host %s\n",
  1017.             info,hostpool[effective_array_of_index[i]]);
  1018.         goto fail;
  1019.         }
  1020.     ack = timeout_wait_message(tid[i],ACKNOLEDGE,effective_array_of_index[i]);
  1021.     if (ack<0)
  1022.         goto fail;
  1023.  
  1024.     info = pvm_recv(tid[i],ACKNOLEDGE);
  1025.     if (info <0)
  1026.         {
  1027.         fprintf(outfile,"\tpvm_recv() : Failed with error %d for host %s\n",
  1028.             info,hostpool[effective_array_of_index[i]]);
  1029.         goto fail;    
  1030.         }
  1031.     }
  1032.  
  1033. info = pvm_setopt(PvmRoute,route);
  1034. if (info <0)
  1035.     {
  1036.     fprintf(outfile,"\tpvm_setopt() : Failed with error %d\n",info);
  1037.     goto fail;
  1038.     }
  1039.  
  1040. if ((is_empty == EMPTY)&&(send_mode == SEND))
  1041.     {
  1042.     if (timing_total||timing_average)
  1043.         gettimeofday(&t1,NULL);
  1044.     for (j=0;j<num_messages;j++)
  1045.         {
  1046.         for (i=1;i<number_of_process;i++)
  1047.             {
  1048.             if ((info = pvm_initsend(data_format)) <0)
  1049.                 {
  1050.                 fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  1051.                 goto fail;
  1052.                 }
  1053.             if ((info = pvm_send(tid[i],FUNNELING))<0)
  1054.                 {
  1055.                 fprintf(outfile,"\tpvm_send() : Failed with error %d for host %s\n",
  1056.                     info,hostpool[effective_array_of_index[i]]);
  1057.                 goto fail;
  1058.                 }
  1059.             }
  1060.         for (i=1;i<number_of_process;i++)
  1061.             {
  1062.             for (count=0;count<BUSY_LOOP_PERF;count++)
  1063.                             if (pvm_probe(-1,FUNNELING)>0)
  1064.                                        break;
  1065.                     if (count== BUSY_LOOP_PERF)
  1066.                             {
  1067.                             fprintf(outfile,"\tTimeout expired \n");
  1068.                             goto fail;
  1069.                             }
  1070.             /*
  1071.             ack = timeout_wait_message(-1,FUNNELING,-1);
  1072.                     if (ack <0)
  1073.                             goto fail;
  1074.             */
  1075.             if ((info = pvm_recv(-1,FUNNELING))<0)
  1076.                 {    
  1077.                 fprintf(outfile,"\tpvm_recv() : Failed with erro %d\n",info);
  1078.                 goto fail;
  1079.                 }
  1080.             }
  1081.         }
  1082.     if (timing_total||timing_average)
  1083.         gettimeofday(&t2,NULL);
  1084.     if (timing_total)
  1085.         {
  1086.             Total_time = TIME_ELAPSED;
  1087.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  1088.         }
  1089.     if (timing_average)
  1090.         {
  1091.             Average_time = TIME_ELAPSED / ((double)num_messages);
  1092.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  1093.         }
  1094.     for (j=1;j<number_of_process;j++)
  1095.         pvm_kill(tid[j]);
  1096.     pvm_setopt(PvmRoute,PvmAllowDirect);
  1097.     free(tid);
  1098.     free(effective_array_of_index);
  1099.     return 1;
  1100.     }
  1101.  
  1102. if ((is_empty == EMPTY)&&(send_mode == MCAST))
  1103.     {
  1104.     if (timing_total||timing_average)
  1105.         gettimeofday(&t1,NULL);
  1106.     for (j=0;j<num_messages;j++)
  1107.         {
  1108.         if ((info = pvm_initsend(data_format))<0)
  1109.             {
  1110.             fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  1111.             goto fail;
  1112.             }
  1113.         if ((info = pvm_mcast(tid+1,number_of_process-1,FUNNELING))<0)
  1114.             {
  1115.             fprintf(outfile,"\tpvm_mcast() : Failed with error %d\n",info);
  1116.             goto fail;
  1117.             }
  1118.         for (i=1;i<number_of_process;i++)
  1119.             {
  1120.             for (count=0;count<BUSY_LOOP_PERF;count++)
  1121.                                 if (pvm_probe(-1,FUNNELING)>0)
  1122.                                         break;
  1123.                         if (count== BUSY_LOOP_PERF)
  1124.                                 {
  1125.                                 fprintf(outfile,"\tTimeout expired\n");
  1126.                                 goto fail;
  1127.                                 }
  1128.             /*
  1129.             ack = timeout_wait_message(-1,FUNNELING,-1);
  1130.                         if (ack <0)
  1131.                                 goto fail;
  1132.             */
  1133.             if ((info = pvm_recv(-1,FUNNELING))<0)
  1134.                 {
  1135.                 fprintf(outfile,"\tpvm_recv() : Failed with error %d\n",info);
  1136.                 goto fail;
  1137.                 }
  1138.             }
  1139.         }
  1140.     if (timing_total||timing_average)
  1141.         gettimeofday(&t2,NULL);
  1142.     if (timing_total)
  1143.         {
  1144.             Total_time = TIME_ELAPSED;
  1145.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  1146.         }
  1147.     if (timing_average)
  1148.         {
  1149.             Average_time = TIME_ELAPSED / ((double)num_messages);
  1150.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  1151.         }
  1152.     for (j=1;j<number_of_process;j++)
  1153.         pvm_kill(tid[j]);
  1154.     pvm_setopt(PvmRoute,PvmAllowDirect);
  1155.     free(tid);
  1156.     free(effective_array_of_index);
  1157.     return 1;
  1158.     }
  1159.  
  1160. if ((is_empty == EMPTY)&&(send_mode = PSEND))
  1161.     {
  1162.     if (timing_total||timing_average)
  1163.         gettimeofday(&t1,NULL);
  1164.     for (j=0;j<num_messages;j++)
  1165.         {
  1166.         for (i=1;i<number_of_process;i++)
  1167.             if ((info = pvm_psend(tid[i],FUNNELING,outbuf,0,PVM_INT))<0)
  1168.                 {
  1169.                 fprintf(outfile,"\tpvm_psend() : Failed with error %d for host %s\n",
  1170.                     info,hostpool[effective_array_of_index[i]]);
  1171.                 goto fail;
  1172.                 }
  1173.         for (i=1;i<number_of_process;i++)
  1174.             {
  1175.             for (count=0;count<BUSY_LOOP_PERF;count++)
  1176.                                 if (pvm_probe(-1,FUNNELING)>0)
  1177.                                         break;
  1178.                         if (count== BUSY_LOOP_PERF)
  1179.                                 {
  1180.                                 fprintf(outfile,"\tTimeout expired\n");
  1181.                                 goto fail;
  1182.                                 }
  1183.             /*
  1184.             ack = timeout_wait_message(-1,FUNNELING,-1);
  1185.                             if (ack <0)
  1186.                                     goto fail;
  1187.             */
  1188.             if ((info = pvm_precv(-1,FUNNELING,inbuf,0,PVM_INT,&atid,&atag,&alen))<0)
  1189.                 {
  1190.                 fprintf(outfile,"\tpvm_precv() : Failed with error %d\n",info);
  1191.                 goto fail;
  1192.                 }
  1193.             }
  1194.         }
  1195.     if (timing_total||timing_average)
  1196.         gettimeofday(&t2,NULL);
  1197.     if (timing_total)
  1198.         {
  1199.             Total_time = TIME_ELAPSED;
  1200.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  1201.         }
  1202.     if (timing_average)
  1203.         {
  1204.             Average_time = TIME_ELAPSED / ((double)num_messages);
  1205.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  1206.         }
  1207.     for (j=1;j<number_of_process;j++)
  1208.                 pvm_kill(tid[j]);
  1209.     pvm_setopt(PvmRoute,PvmAllowDirect);
  1210.     free(tid);
  1211.     free(effective_array_of_index);
  1212.     return 1;
  1213.     }
  1214.  
  1215. /* From here, is_empty == NOT_EMPTY */
  1216.  
  1217. if (send_mode == SEND)
  1218.     {
  1219.     if (timing_total||timing_average)
  1220.         gettimeofday(&t1,NULL);
  1221.     for (j=0;j<num_messages;j++)
  1222.         {
  1223.         for (i=1;i<number_of_process;i++)
  1224.             {
  1225.             if ((info = pvm_initsend(data_format))<0)
  1226.                 {
  1227.                 fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  1228.                 goto fail;
  1229.                 }
  1230.             if ((info = pvm_pkint(outbuf,messages_length,1))<0)
  1231.                 {
  1232.                 fprintf(outfile,"\tpvm_pkint() : Failed with error %d\n",info);
  1233.                 goto fail;
  1234.                 }
  1235.             if ((info = pvm_send(tid[i],FUNNELING))<0)
  1236.                 {
  1237.                 fprintf(outfile,"\tpvm_send() : Failed with error %d\n",info);
  1238.                 goto fail;
  1239.                 }
  1240.             }
  1241.         for (i=1;i<number_of_process;i++)
  1242.             {
  1243.             for (count=0;count<BUSY_LOOP_PERF;count++)
  1244.                                 if (pvm_probe(-1,FUNNELING)>0)
  1245.                                         break;
  1246.                         if (count== BUSY_LOOP_PERF)
  1247.                                 {
  1248.                                 fprintf(outfile,"\tTimeout expired \n");
  1249.                                 goto fail;
  1250.                                 }
  1251.             /*
  1252.             ack = timeout_wait_message(-1,FUNNELING,-1);
  1253.                                 if (ack <0)
  1254.                                         goto fail;
  1255.             */
  1256.             if ((info = pvm_recv(-1,FUNNELING))<0)
  1257.                 {
  1258.                 fprintf(outfile,"\tpvm_recv() : Failed with error %d\n",info);
  1259.                 goto fail;
  1260.                 }
  1261.             if ((info = pvm_upkint(inbuf,messages_length,1))<0)
  1262.                 {
  1263.                 fprintf(outfile,"\tpvm_upkint() : Failed with error %d\n",info);
  1264.                 goto fail;
  1265.                 }
  1266.             }
  1267.         }
  1268.     if (timing_total||timing_average)
  1269.         gettimeofday(&t2,NULL);
  1270.     if (timing_total)
  1271.         {
  1272.             Total_time = TIME_ELAPSED;
  1273.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  1274.         }
  1275.     if (timing_average)
  1276.         {
  1277.             Average_time = TIME_ELAPSED / ((double)num_messages);
  1278.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  1279.         }
  1280.     for (j=1;j<number_of_process;j++)
  1281.                 pvm_kill(tid[j]);
  1282.     pvm_setopt(PvmRoute,PvmAllowDirect);
  1283.     free(tid);
  1284.     free(effective_array_of_index);
  1285.     return 1;
  1286.     }
  1287.  
  1288. if (send_mode == MCAST)
  1289.     {
  1290.     if (timing_total||timing_average)
  1291.         gettimeofday(&t1,NULL);
  1292.     for (j=0;j<num_messages;j++)
  1293.         {
  1294.         if ((info = pvm_initsend(data_format))<0)
  1295.             {    
  1296.             fprintf(outfile,"\tpvm_initsend() : Failed with error %d\n",info);
  1297.             goto fail;
  1298.             }
  1299.         if ((info = pvm_pkint(outbuf,messages_length,1))<0)
  1300.             {
  1301.             fprintf(outfile,"\tpvm_pkinf() : Failed with error %d\n",info);
  1302.             goto fail;
  1303.             }
  1304.         if ((info = pvm_mcast(tid+1,number_of_process-1,FUNNELING))<0)
  1305.             {
  1306.             fprintf(outfile,"\tpvm_mcast() : Failed with error %d\n",info);
  1307.             goto fail;
  1308.             }
  1309.         for (i=1;i<number_of_process;i++)
  1310.             {
  1311.             for (count=0;count<BUSY_LOOP_PERF;count++)
  1312.                                 if (pvm_probe(-1,FUNNELING)>0)
  1313.                                         break;
  1314.                         if (count== BUSY_LOOP_PERF)
  1315.                                 {
  1316.                                 fprintf(outfile,"\tTimeout expired\n");
  1317.                                 goto fail;
  1318.                                 }
  1319.             /*
  1320.             ack = timeout_wait_message(-1,FUNNELING,-1);
  1321.                         if (ack <0)
  1322.                                 goto fail;
  1323.             */
  1324.             if ((info = pvm_recv(-1,FUNNELING))<0)
  1325.                 {
  1326.                 fprintf(outfile,"\tpvm_recv() : Failed with error %d\n",info);
  1327.                 goto fail;
  1328.                 }
  1329.             if ((info = pvm_upkint(inbuf,messages_length,1))<0)
  1330.                 {
  1331.                 fprintf(outfile,"\tpvm_upkint() : Failed with error %d\n",info);
  1332.                 goto fail;
  1333.                 }
  1334.             }
  1335.         }
  1336.     if (timing_total||timing_average)
  1337.         gettimeofday(&t2,NULL);
  1338.     if (timing_total)
  1339.         {
  1340.             Total_time = TIME_ELAPSED;
  1341.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  1342.         }
  1343.     if (timing_average)
  1344.         {
  1345.             Average_time = TIME_ELAPSED / ((double)num_messages);
  1346.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  1347.         }
  1348.     for (j=1;j<number_of_process;j++)
  1349.                 pvm_kill(tid[j]);
  1350.     pvm_setopt(PvmRoute,PvmAllowDirect);
  1351.     free(tid);
  1352.     free(effective_array_of_index);
  1353.     return 1;
  1354.     }
  1355.  
  1356. if (send_mode == PSEND)
  1357.     {
  1358.     if (timing_total||timing_average)
  1359.         gettimeofday(&t1,NULL);
  1360.     for (j=0;j<num_messages;j++)
  1361.         {
  1362.         for (i=1;i<number_of_process;i++)
  1363.             if ((info = pvm_psend(tid[i],FUNNELING,outbuf,messages_length,PVM_INT))<0)
  1364.                 {
  1365.                 fprintf(outfile,"\tpvm_psend() : Failed with error %d for host %s\n",
  1366.                     info,hostpool[effective_array_of_index[i]]);
  1367.                 goto fail;
  1368.                 }
  1369.         for (i=1;i<number_of_process;i++)
  1370.             {
  1371.             for (count=0;count<BUSY_LOOP_PERF;count++)
  1372.                                 if (pvm_probe(-1,FUNNELING)>0)
  1373.                                         break;
  1374.                         if (count== BUSY_LOOP_PERF)
  1375.                                 {
  1376.                                 fprintf(outfile,"\tTimeout expired\n");
  1377.                                 goto fail;
  1378.                                 }
  1379.             /*
  1380.             ack = timeout_wait_message(-1,FUNNELING,-1);
  1381.                         if (ack <0)
  1382.                                 goto fail;
  1383.             */
  1384.             if ((info = pvm_precv(-1,FUNNELING,inbuf,
  1385.                 messages_length,PVM_INT,&atid,&atag,&alen))<0)
  1386.                 {
  1387.                 fprintf(outfile,"\tpvm_precv() : Failed with error %d\n",info);
  1388.                 goto fail;
  1389.                 }
  1390.             }
  1391.         }
  1392.     if (timing_total||timing_average)
  1393.         gettimeofday(&t2,NULL);
  1394.     if (timing_total)
  1395.         {
  1396.             Total_time = TIME_ELAPSED;
  1397.             fprintf(outfile,"\t Total time = %f sec.\n",Total_time);
  1398.         }
  1399.     if (timing_average)
  1400.         {
  1401.             Average_time = TIME_ELAPSED / ((double)num_messages);
  1402.             fprintf(outfile,"\t Average time = %f sec.\n",Average_time);
  1403.         }
  1404.     for (j=1;j<number_of_process;j++)
  1405.                 pvm_kill(tid[j]);
  1406.     pvm_setopt(PvmRoute,PvmAllowDirect);
  1407.     free(tid);
  1408.     free(effective_array_of_index);
  1409.     return 1;
  1410.     }
  1411.  
  1412. fail :
  1413. for (i=1;i<number_of_process;i++)
  1414.     pvm_kill(tid[i]);
  1415. free(tid);
  1416. free(effective_array_of_index);
  1417. pvm_setopt(PvmRoute,PvmAllowDirect);
  1418. return -1;
  1419. }
  1420.     
  1421.  
  1422.     
  1423. /*      SLAVE   */
  1424. void funneling_slave(is_empty,send_mode,route,data_format)
  1425. int    is_empty;
  1426. int    send_mode;
  1427. int    route;
  1428. int    data_format;
  1429. {
  1430. int     *inbuf;
  1431. int     *outbuf;
  1432. int    atid,atag,alen;
  1433. int    length;
  1434.  
  1435. pvm_recv(pvm_parent(),ACKNOLEDGE);
  1436. pvm_upkint(&length,1,1);
  1437.  
  1438. inbuf = (int *)malloc(sizeof(int)*length);
  1439. outbuf = (int *)malloc(sizeof(int)*length);
  1440.  
  1441. pvm_initsend(PvmDataDefault);
  1442. pvm_send(pvm_parent(),ACKNOLEDGE);
  1443. pvm_setopt(PvmRoute,route);
  1444.  
  1445. if ((is_empty == EMPTY)&&((send_mode == SEND)||(send_mode == MCAST)))
  1446.         {
  1447.     while(1)
  1448.                 {
  1449.                 pvm_recv(pvm_parent(),FUNNELING);
  1450.                 pvm_initsend(data_format);
  1451.                 pvm_send(pvm_parent(),FUNNELING);
  1452.                 }
  1453.         }
  1454. if ((is_empty == EMPTY)&&(send_mode == PSEND))
  1455.         {
  1456.         while(1)
  1457.                 {
  1458.                 pvm_precv(pvm_parent(),FUNNELING,inbuf,0,PVM_INT,&atid,&atag,&alen);
  1459.                 pvm_psend(pvm_parent(),FUNNELING,outbuf,0,PVM_INT);
  1460.                 }
  1461.         }
  1462. if ((send_mode == SEND)||(send_mode == MCAST))
  1463.         {
  1464.     while(1)
  1465.                 {
  1466.                 pvm_recv(pvm_parent(),FUNNELING);
  1467.         pvm_upkint(inbuf,length,1);
  1468.                 pvm_initsend(data_format);
  1469.         pvm_pkint(outbuf,length,1);
  1470.                 pvm_send(pvm_parent(),FUNNELING);
  1471.                 }
  1472.         }
  1473.  
  1474. if (send_mode == PSEND)
  1475.         {
  1476.     while(1)
  1477.                 {
  1478.                 pvm_precv(pvm_parent(),FUNNELING,inbuf,length,PVM_INT,&atid,&atag,&alen);
  1479.                 pvm_psend(pvm_parent(),FUNNELING,outbuf,length,PVM_INT);
  1480.                 }
  1481.         }
  1482. pvm_exit();
  1483. }
  1484.  
  1485.